package main

import (
	"flag"
	"fmt"
	_"runtime"
	"GoServer/conf"
	"GoServer/database"
	"GoServer/game"
	"GoServer/gate"
	"GoServer/login"
	"GoServer/msgbackend"
	"GoServer/user"

	"github.com/name5566/leaf"
	lconf "github.com/name5566/leaf/conf"
)

func init() {
	// 初始化 日志系统
	flag.Set("alsologtostderr", "false") // 日志写入文件的同时，输出到stderr
	flag.Set("log_dir", "./log")        // 日志文件保存目录
	flag.Set("v", "1")                  // 配置V输出的等级。
	flag.Parse()
	return
}

func main() {
	//初始化配置
	if !database.Run() {
		fmt.Println("init errors")
	}

	//服务器开发利用cpu多核
	// fmt.Println("本机几核")
	// fmt.Println(runtime.NumCPU())
	// runtime.GOMAXPROCS(runtime.NumCPU())

	//数据库连接
	database.Connect()
	//redis初始化连接
	if !msgbackend.RedisContent() {
		fmt.Println("redis connect init failed")
		return
	}
	//监听自身连接池
	//msgbackend.GetChannel()

	user.UserInfoCacheInit()

	//redis监听连接池(监听服务端数据)
	msgbackend.ChargeServiceInit()

	lconf.LogLevel = conf.Server.LogLevel
	lconf.LogPath = conf.Server.LogPath
	lconf.LogFlag = conf.LogFlag
	lconf.ConsolePort = conf.Server.ConsolePort
	lconf.ProfilePath = conf.Server.ProfilePath

	leaf.Run(
		game.Module,
		gate.Module,
		login.Module,
	)

}
